<h1>
    <?php if ($this->mode == INSERT_MODE): ?>
        Add New User
    <?php else: ?>
        Edit User
    <?php endif; ?>
</h1>
<?php $user = $this->user ?>
<?php $action = $this->mode == INSERT_MODE ? 'newuser' : 'edituser' ?>
<?php $action_url = $this->url(array('action' => $action)) ?>
<form id='frm_newuser' method='POST' action='<?php echo $action_url ?>' autocomplete="off">
    <div class='wrap-content'>
        <label>
            User Name
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <input type='text' name='username' id='username' value='<?php echo $this->mode == EDIT_MODE ? $user->username : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'username')) ?>
            </div>
        </div>
    </div>
    <div class='wrap-content'>
        <label>
            Password
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <input type='text' name='password' id='password' value='<?php echo $this->mode == EDIT_MODE ? $user->password : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'password')) ?>
            </div>
        </div> 
    </div>     
    <div class='wrap-content'>
        <label>
            Fullname
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <input type='text' name='fullname' id='fullname' value='<?php echo $this->mode == EDIT_MODE ? $user->fullname : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'fullname')) ?>
            </div>
        </div> 
    </div>            
    <div class='wrap-content'>
        <label>
            Email
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <input type='text' name='email' id='email' value='<?php echo $this->mode == EDIT_MODE ? $user->email : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'email')) ?>
            </div>
        </div> 
    </div>    
    <div class='wrap-content'>
        <label>
            Phone
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <input type='text' name='phone' id='phone' value='<?php echo $this->mode == EDIT_MODE ? $user->phone : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'phone')) ?>
            </div>
        </div> 
    </div>      
    <div class='wrap-content'>
        <label>
            Address
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <input type='text' name='address' id='address' value='<?php echo $this->mode == EDIT_MODE ? $user->address : "" ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'address')) ?>
            </div>
        </div> 
    </div>   
    <div class='wrap-content'>
        <label>
            Country
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <select name='country'  id='country'>
                    <?php foreach ($this->countries as $country): ?>
                        <option value='<?php echo $country ?>' <?php echo $this->mode == EDIT_MODE && $this->user->country == $country ? "selected" : "" ?>><?php echo $country ?></option>
                    <?php endforeach; ?>
                </select>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'country')) ?>
            </div>
        </div> 
    </div>                                                                        
    <div class='wrap-content'>
        <label>
            Role
        </label>                  
        <div class='content'>                          
            <div class='wrap-input'>
                <select id='role' name='role'>
                    <?php foreach ($this->roles as $role): ?>
                        <option value='<?php echo $role ?>' <?php echo $this->mode == EDIT_MODE && $user->role == $role ? "selected" : "" ?>><?php echo $role ?></option>
                    <?php endforeach; ?>
                </select>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'role')) ?>
            </div>
            <div class='wrap-input'>
                <input type='submit' class='submit-button' />
                <a href='<?php echo $this->baseUrl() ?>/admin/index/users'>
                    <input type='button' class='submit-button' value='Cancel'/>
                </a>
            </div>
        </div> 
    </div>                                   
</form>  
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js'></script>
<script src='<?php echo $this->baseUrl()?>/public/js/admin/newuser.js'></script>